package com.umeng.kaoti5;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.umeng.kaoti5.adapter.FragmentAdapter;
import com.umeng.kaoti5.fragment.FirstFragment;
import com.umeng.kaoti5.fragment.FourFragment;
import com.umeng.kaoti5.fragment.ThreeFragment;
import com.umeng.kaoti5.fragment.TwoFragment;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.view_vp)
    ViewPager viewVp;
    @BindView(R.id.tab)
    TabLayout tab;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        initData();
    }

    private void initData() {
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(new FirstFragment());
        fragments.add(new TwoFragment());
        fragments.add(new ThreeFragment());
        fragments.add(new FourFragment());

        List<String>  titles = new ArrayList<>();
        titles.add("首页");
        titles.add("消息");
        titles.add("咨询");
        titles.add("我");

        FragmentAdapter fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(), fragments, titles);
        viewVp.setAdapter(fragmentAdapter);
        tab.setupWithViewPager(viewVp);


    }
}